package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppLotteryRecord;
import com.ruoyi.background.service.IAppLotteryRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 积分抽奖记录Controller
 *
 * @author susu
 * @date 2024-08-24
 */
@RestController
@RequestMapping("/applet/lotteryRecord")
public class AppLotteryRecordController extends BaseController {
    @Autowired
    private IAppLotteryRecordService appLotteryRecordService;

    /**
     * 查询积分抽奖记录列表
     */
    @PreAuthorize("@ss.hasPermi('applet:lotteryRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppLotteryRecord appLotteryRecord) {
        startPage();
        List<AppLotteryRecord> list = appLotteryRecordService.selectAppLotteryRecordList(appLotteryRecord);
        return getDataTable(list);
    }

    /**
     * 导出积分抽奖记录列表
     */
    @PreAuthorize("@ss.hasPermi('applet:lotteryRecord:export')")
    @Log(title = "积分抽奖记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppLotteryRecord appLotteryRecord) {
        appLotteryRecordService.exportUserLotteryRecord(response,appLotteryRecord);
    }

    /**
     * 获取积分抽奖记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:lotteryRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appLotteryRecordService.selectAppLotteryRecordById(id));
    }

    /**
     * 新增积分抽奖记录
     */
    @PreAuthorize("@ss.hasPermi('applet:lotteryRecord:add')")
    @Log(title = "积分抽奖记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppLotteryRecord appLotteryRecord) {
        return toAjax(appLotteryRecordService.insertAppLotteryRecord(appLotteryRecord));
    }

    /**
     * 修改积分抽奖记录
     */
    @PreAuthorize("@ss.hasPermi('applet:lotteryRecord:edit')")
    @Log(title = "积分抽奖记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppLotteryRecord appLotteryRecord) {
        return toAjax(appLotteryRecordService.updateAppLotteryRecord(appLotteryRecord));
    }

    /**
     * 删除积分抽奖记录
     */
    @PreAuthorize("@ss.hasPermi('applet:lotteryRecord:remove')")
    @Log(title = "积分抽奖记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appLotteryRecordService.deleteAppLotteryRecordByIds(ids));
    }
}
